let connection = require('./db')
module.exports = {
    // 添加参数： 每页多少条pagesize，当前页nowPage
    getArticles: (pagesize, nowPage, cb) => {
      let sqlStr = 'select articles.*, users.nickname from articles left join users on articles.authorId=users.id limit ? offset ?;select count(*) AS totalCount from articles;'
      // 偏移量= 每页多少条*(当前页码-1)
      let offsetVal = pagesize*(nowPage - 1)
      connection.query(sqlStr,[pagesize, offsetVal], (err, results) => {
        if (err) return cb(err, null)
        cb(null, results)
      })
    }
  };